package com.example.mobile2021606144ywr0325;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements  View.OnClickListener{


    private TextView tvMainTitle;
    private EditText editTxtMainShow;
    private Button btnMainBack;
    private Button btnMainDiv;
    private Button btnMainMc;
    private Button btnMainMul;
    private Button btnMainSub;
    private Button btnMainNum9;
    private Button btnMainNum8;
    private Button btnMainNum7;
    private Button btnMainNum4;
    private Button btnMainNum5;
    private Button btnMainNum6;
    private Button btnMainPersent;
    private Button btnMainNum1;
    private Button btnMainNum2;
    private Button btnMainNum3;
    private Button btnMainAdd;
    private Button btnMainNum0;
    private Button btnMainPoint;
    private Button btnMainEqual;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initView();
        btnMainNum0.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTxtMainShow.append("0");
            }
        });
        btnMainNum1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTxtMainShow.append("1");
            }
        });
        btnMainNum2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTxtMainShow.append("2");
            }
        });
        btnMainNum3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTxtMainShow.append("3");
            }
        });
        btnMainNum4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editTxtMainShow.append("4");
            }
        });

    }

    @Override
    public void onClick(View v) {
        Button btn=(Button)v;
        int id=btn.getId();
        switch (id){
            case R.id.btn_main_num0:
                editTxtMainShow.append("0");
                break;
            case R.id.btn_main_num1:
                editTxtMainShow.append("1");
                break;
            case R.id.btn_main_num2:
                editTxtMainShow.append("2");
                break;
            case R.id.btn_main_num3:
                editTxtMainShow.append("3");
                break;
            case R.id.btn_main_num4:
                editTxtMainShow.append("4");
                break;
            case R.id.btn_main_num5:
                editTxtMainShow.append("5");
                break;
            case R.id.btn_main_num6:
                editTxtMainShow.append("6");
                break;
            case R.id.btn_main_num7:
                editTxtMainShow.append("7");
                break;
            case R.id.btn_main_num8:
                editTxtMainShow.append("8");
                break;
            case R.id.btn_main_num9:
                editTxtMainShow.append("9");
                break;
            case R.id.btn_main_back:
                editTxtMainShow.setText(null);
                break;
            case R.id.btn_main_mul:
                String msg=editTxtMainShow.getText().toString();
                if(msg.length()>1);
            {
                editTxtMainShow.setText(msg.substring(0, msg.length() - 1));
            }
                break;
            }
        }


    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        editTxtMainShow = (EditText) findViewById(R.id.editTxt_main_show);
        btnMainBack = (Button) findViewById(R.id.btn_main_back);
        btnMainDiv = (Button) findViewById(R.id.btn_main_div);
        btnMainMc = (Button) findViewById(R.id.btn_main_mc);
        btnMainMul = (Button) findViewById(R.id.btn_main_mul);
        btnMainSub = (Button) findViewById(R.id.btn_main_sub);
        btnMainNum9 = (Button) findViewById(R.id.btn_main_num9);
        btnMainNum8 = (Button) findViewById(R.id.btn_main_num8);
        btnMainNum7 = (Button) findViewById(R.id.btn_main_num7);
        btnMainNum4 = (Button) findViewById(R.id.btn_main_num4);
        btnMainNum5 = (Button) findViewById(R.id.btn_main_num5);
        btnMainNum6 = (Button) findViewById(R.id.btn_main_num6);
        btnMainPersent = (Button) findViewById(R.id.btn_main_persent);
        btnMainNum1 = (Button) findViewById(R.id.btn_main_num1);
        btnMainNum2 = (Button) findViewById(R.id.btn_main_num2);
        btnMainNum3 = (Button) findViewById(R.id.btn_main_num3);
        btnMainAdd = (Button) findViewById(R.id.btn_main_add);
        btnMainNum0 = (Button) findViewById(R.id.btn_main_num0);
        btnMainPoint = (Button) findViewById(R.id.btn_main_point);
        btnMainEqual = (Button) findViewById(R.id.btn_main_equal);
    }


}